from sqlalchemy import Column, BigInteger,Integer, String
from bmaster.database import Base

class User(Base):
    __tablename__ = 'user'
    id = Column(BigInteger(20), primary_key = True)
    openid = Column(String(255))
    unionid = Column(String(255))
    name = Column(String(255))
    wechat_number = Column(String(255))
    email = Column(String(255))
    avatar = Column(Stirng(255))
    accounts = relationship("Account") 

    def __init__(self, name, wechat_number, email = None):
    	self.name = name
    	self.wechat_number = wechat_number
    	self.email = email

class Account(Base):
	__tablename__ = 'account'
	id = Column(BigInteger(20), primary_key = True)
	username = Column(String(255), unique=True)
	password = Column(String(255))
	balance = Column(Integer(11))
	type = Column(Integer(11))
	user_id = Column(BigInteger(20), ForeignKey('user.id'))

	def __init__(self, username, password):
		self.username = username
		self.password = password
		
class Host(Base):
    __tablename__ = 'host'
    id = Column(BigInteger(20), primary_key = True)
    region = Column(String(255))
    provider = Column(String(255))
    ssh_username = Column(String(255))
    ssh_private_key = Column(String(255))
    ip = Column(String(255))
    accounts = relationship("Account")
    
    def __init__(self, ip, ssh_username, ssh_private_key):
        self.ip = ip
        self.ssh_username = ssh_username
        self.ssh_private_key = ssh_private_key

class Traffic(Base):
    __tablename__ = 'traffic'
    id = Column(BigInteger(20), primary_key = True)
    total = Column(Integer(11))
    day = Column(Integer(11))
    week = Column(Integer(11))
    month = Column(Integer(11))
    account_id = Column(BigInteger(20), ForeignKey('account.id'))
    account = relationship("Account", back_populates="traffic")

